﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using DTO.Models;

namespace CIT.Controllers
{
    public class LienheController : Controller
    {
        //
        // GET: /Lienhe/

        public ActionResult Index()
        {
            DataRepository dr = new DataRepository();
            List<MEDIA> dsGioiThieu = dr.MediaProvider.getMediaOut("lienhe").ToList<MEDIA>();
            if (dsGioiThieu == null || dsGioiThieu.Count == 0)
                return View("Error");

            MEDIA obj = dsGioiThieu[0];
            obj.Content = HttpUtility.HtmlDecode(obj.Content);
            return View(obj);
        }

        [HttpPost()]
        public JsonResult SaveFeedback(string[] param)
        {
            if (param == null || param.Length < 0)
                return this.Json(new { mess = "fail" }, JsonRequestBehavior.AllowGet);

            FEEDBACK obj = new FEEDBACK();
            obj.Name = param[0];
            obj.Email = param[1];
            obj.FeedbackContent = param[2];
            obj.IsAnswered = false;
            obj.Date = DateTime.Now;
            DataRepository dr = new DataRepository();
            dr.FeedbackProvider.Insert(obj);

            return this.Json(new { mess = "success", result = param }, JsonRequestBehavior.AllowGet);
        }
    }
}
